﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using XiaoGang.Soft.XGWMS.COM;

namespace XiaoGang.Soft.XGWMS.DAL_SQL
{
    public class DAL_M009_STORAGE_INPUT
    {
        /// <summary>
        /// <p><b>方法名称</b>Init_Combox</p>	
        /// <p><b>概要説明  :</b>ComBox控件的初始化</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>
        /// <returns type = "ReturnValue">执行结果信息</returns>
        public ReturnValue Init_Combox()
        {
            return XGWMS.DBUtility.SqlHelper.Query(DAL_M009_STORAGE_INPUT_SQL.Init_Combox_SQL);
        }

        /// <summary>
        /// <p><b>方法名称</b>GetSingleData</p>	
        /// <p><b>概要説明  :</b>取得单条库存信息</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">检索条件</param>
        /// <returns type = "ReturnValue">执行结果信息</returns>
        public ReturnValue GetSingleData(MODEL.MOD_M009_STORAGE_INPUT model)
        {
            SqlParameter parameter = new SqlParameter("@STORAGE_ID", SqlDbType.Char, 12);
            parameter.Value = model.STORAGE_ID.Trim();
            return XGWMS.DBUtility.SqlHelper.Query(DAL_SQL.DAL_M009_STORAGE_INPUT_SQL.Get_Single_Data_SQL, parameter);
        }

        /// <summary>
        /// <p><b>方法名称</b>GetSingleGoods</p>	
        /// <p><b>概要説明  :</b>取得单条商品信息</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">检索条件</param>
        /// <returns type = "ReturnValue">执行结果信息</returns>
        public ReturnValue GetSingleGoods(MODEL.MOD_M009_STORAGE_INPUT model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@GOODS_ID", SqlDbType.Char,12),
					new SqlParameter("@STOREROOM_ID", SqlDbType.Char,12)};
            parameters[0].Value = model.GOODS_ID;
            parameters[1].Value = model.STOREROOM_ID;
            return XGWMS.DBUtility.SqlHelper.Query(DAL_SQL.DAL_M009_STORAGE_INPUT_SQL.Get_Single_Goods_SQL, parameters);
        }

        /// <summary>
        /// <p><b>方法名称</b>AddGoodsCount</p>	
        /// <p><b>概要説明  :</b>更新商品数量信息</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">更新信息和条件</param>
        /// <returns type = "ReturnValue">执行结果信息</returns>
        public ReturnValue AddGoodsCount(MODEL.MOD_M009_STORAGE_INPUT model)
        {
            SqlParameter[] parameters = {					
					new SqlParameter("@TRANS_STATE", SqlDbType.Char,1),					
					new SqlParameter("@GOODS_ID", SqlDbType.Char,12),					
					new SqlParameter("@UNITS", SqlDbType.Int,4)};
            parameters[0].Value = model.TRANS_STATE;
            parameters[1].Value = model.GOODS_ID;
            parameters[2].Value = model.UNITS;

            return XGWMS.DBUtility.SqlHelper.ExecuteSql(DAL_M009_STORAGE_INPUT_SQL.Add_Goods_Count_SQL, parameters);
        }

        /// <summary>
        /// <p><b>方法名称</b>InsertProcess</p>	
        /// <p><b>概要説明  :</b>库存商品信息的插入</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/03</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">插入信息</param>
        /// <returns type = "ReturnValue">执行结果信息</returns>
        public ReturnValue InsertProcess(MODEL.MOD_M009_STORAGE_INPUT model)
        { 
            SqlParameter[] parameters = {			
					new SqlParameter("@UPDATER_ID", SqlDbType.VarChar,12),
					new SqlParameter("@TERMINAL_CD", SqlDbType.VarChar,256),
					new SqlParameter("@STORAGE_ID", SqlDbType.Char,12),
					new SqlParameter("@STOREROOM_ID", SqlDbType.Char,12),
					new SqlParameter("@GOODS_ID", SqlDbType.Char,12),
					new SqlParameter("@UNITS", SqlDbType.Int),
					new SqlParameter("@MEMO", SqlDbType.Char,256),
                    new SqlParameter("@PRODUCE_DATE", SqlDbType.Char,8),
                    new SqlParameter("@OVER_PRODUCE_DATE", SqlDbType.Char,8),
                    new SqlParameter("@BUYING_PRICE", SqlDbType.Money),
                    new SqlParameter("@SELLING_PRICE", SqlDbType.Money),
                    new SqlParameter("@BILL_ID", SqlDbType.Char,12),
                    new SqlParameter("@RED_BLACK", SqlDbType.Char,1)};
			parameters[0].Value = model.UPDATER_ID;
			parameters[1].Value = model.TERMINAL_CD;
			parameters[2].Value = model.STORAGE_ID;
			parameters[3].Value = model.STOREROOM_ID;
			parameters[4].Value = model.GOODS_ID;
			parameters[5].Value = model.UNITS;
			parameters[6].Value = model.MEMO;
            parameters[7].Value = model.PRODUCE_DATE;
            parameters[8].Value = model.OVER_PRODUCE_DATE;
            if (model.BUYING_PRICE < 0)
            {
                parameters[9].Value = 0;
            }
            else
            {
                parameters[9].Value = model.BUYING_PRICE;
            }
            if (model.SELLING_PRICE < 0)
            {
                parameters[10].Value = 0;
            }
            else
            {
                parameters[10].Value = model.SELLING_PRICE;
            }
            parameters[11].Value = model.BILL_ID;
            parameters[12].Value = model.RED_BLACK;
            return XGWMS.DBUtility.SqlHelper.ExecuteSql(DAL_M009_STORAGE_INPUT_SQL.Insert_STORAGE_SQL, parameters);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strGoodsID"></param>
        /// <param name="strBillID"></param>
        /// <returns></returns>
        public ReturnValue Get_billIdGoodsId(string strGoodsID, string strBillID)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@GOODS_ID", SqlDbType.Char,12),
					new SqlParameter("@BILL_ID", SqlDbType.Char,12)};
            parameters[0].Value = strGoodsID;
            parameters[1].Value = strBillID;
            return XGWMS.DBUtility.SqlHelper.Query(DAL_SQL.DAL_M009_STORAGE_INPUT_SQL.Get_billIdGoodsId_SQL, parameters);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ReturnValue Update_StorageUnits(MODEL.MOD_M009_STORAGE_INPUT model)
        {
            SqlParameter[] parameters = {new SqlParameter("@UPDATER_ID", SqlDbType.VarChar,12),
					new SqlParameter("@TERMINAL_CD", SqlDbType.VarChar,256),
					new SqlParameter("@GOODS_ID", SqlDbType.Char,12),
					new SqlParameter("@UNITS", SqlDbType.Int),
                    new SqlParameter("@BILL_ID", SqlDbType.Char,12)};
            parameters[0].Value = model.UPDATER_ID;
            parameters[1].Value = model.TERMINAL_CD;
            parameters[2].Value = model.GOODS_ID;
            parameters[3].Value = model.UNITS;
            parameters[4].Value = model.BILL_ID;
            return XGWMS.DBUtility.SqlHelper.ExecuteSql(DAL_M009_STORAGE_INPUT_SQL.Update_StorageUnits_SQL, parameters);
        }
    }
}
